﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoBackupDatabase.DBConection;
using System.Data;
using System.Data.SqlClient;
using AutoBackupDatabase.ENT;

namespace AutoBackupDatabase
{
    public class GROUPUSERDAL
    {
         private DbConnection conn;
         public GROUPUSERDAL()
        {
            conn = new DbConnection();
        }

         public List<GROUPUSERENT> GET_GROUPUSER_ALL()
         {
             string query = string.Format("exec GET_GROUPUSER_ALL ");
             DataTable ds = conn.executeGetQuery(query);
             List<GROUPUSERENT> List = new List<GROUPUSERENT>();
             try
             {
                 foreach (DataRow item in ds.Rows)
                 {
                     GROUPUSERENT GROUPUSERent = new GROUPUSERENT();
                     GROUPUSERent.GROUPUSERCODE = int.Parse(item["GROUPUSERCODE"].ToString());
                     GROUPUSERent.GROUPUSERNAME = item["GROUPUSERNAME"].ToString();
                     GROUPUSERent.GROUPUSERDESCRIPTION = item["GROUPUSERDESCRIPTION"].ToString();
                     GROUPUSERent.USERCREATE = item["USERCREATE"].ToString();
                     GROUPUSERent.DATECREATE = DateTime.Parse(item["DATECREATE"].ToString());
                     GROUPUSERent.USERUPDATE = item["USERUPDATE"].ToString();
                     GROUPUSERent.LASTUPDATE = DateTime.Parse(item["LASTUPDATE"].ToString());
                     List.Add(GROUPUSERent);
                 }

                 return List;
             }
             catch (Exception)
             {

                 return List;
             }
            
            

             
         }
         public bool INSERTGROUPUSER(GROUPUSERENT ent)
         {
             string query = "exec  INSERTGROUPUSER @GROUPUSERNAME,@GROUPUSERDESCRIPTION,@USERCREATE";
             SqlParameter[] sqlParameters = new SqlParameter[3];
             
             sqlParameters[0] = new SqlParameter("@GROUPUSERNAME", SqlDbType.NVarChar);
             sqlParameters[0].Value = Convert.ToString(ent.GROUPUSERNAME);

             sqlParameters[1] = new SqlParameter("@GROUPUSERDESCRIPTION", SqlDbType.NVarChar);
             sqlParameters[1].Value = ent.GROUPUSERDESCRIPTION;
             sqlParameters[2] = new SqlParameter("@USERCREATE", SqlDbType.NVarChar);
             sqlParameters[2].Value = Convert.ToString(ent.USERCREATE);
             return conn.executeInsertQuery(query, sqlParameters);
         }
         public bool UPDATEGROUPUSERBYGROUPUSERID(GROUPUSERENT ent)
         {
             string query = "exec  UPDATEGROUPUSERBYGROUPUSERID @GROUPUSERCODE,@GROUPUSERNAME,@GROUPUSERDESCRIPTION,@USERUPDATE";
             SqlParameter[] sqlParameters = new SqlParameter[4];
             sqlParameters[0] = new SqlParameter("@GROUPUSERCODE", SqlDbType.Int);
             sqlParameters[0].Value = Convert.ToString(ent.GROUPUSERCODE);
             sqlParameters[1] = new SqlParameter("@GROUPUSERNAME", SqlDbType.NVarChar);
             sqlParameters[1].Value = Convert.ToString(ent.GROUPUSERNAME);
             sqlParameters[2] = new SqlParameter("@GROUPUSERDESCRIPTION", SqlDbType.NVarChar);
             sqlParameters[2].Value = ent.GROUPUSERDESCRIPTION;
             sqlParameters[3] = new SqlParameter("@USERUPDATE", SqlDbType.NVarChar);
             sqlParameters[3].Value = Convert.ToString(ent.USERCREATE);
             return conn.executeUpdateQuery(query, sqlParameters);
         }
         public bool DELTELEGROUPUSERBYGROUPUSERID(GROUPUSERENT ent)
         {
             string query = "exec  DELTELEGROUPUSERBYGROUPUSERID @GROUPUSERCODE";
             SqlParameter[] sqlParameters = new SqlParameter[1];
             sqlParameters[0] = new SqlParameter("@GROUPUSERCODE", SqlDbType.Int);
             sqlParameters[0].Value = Convert.ToString(ent.GROUPUSERCODE);
             return conn.executeDeleteQuery(query, sqlParameters);
         }
    }
}
